<?php

namespace app\goods\controller;

use think\Controller;
use think\Request;

class GoodsController extends Controller
{
    public function _initialize()
    {
        $request = Request::instance();
        $controller = $request->controller(); // 获取访问的控制器名
        $action = $request->action(); // 获取访问的方法名
        $wantnode = $controller.'-'.$action;
//        dump($wantnode);
//        dump($wantnode);
//        dump($wantnode);
//        dump(session('node'));

        // 通过接口获得平台发送的消息
        $url = 'http://www.miaozy.cn/news?token=3116b736c0a7e0830d38102d5ee140cc';
        $msg = https_request($url);
        $msg = json_decode($msg,true);
        session('wdcount',$msg['wdcount']);



        // 查询待实名审核数量并存入session
        $shimingshenhecount = db('user_data')
            ->where('smstatus',2)
            ->count('uid');
        $shimingshenhecount = empty($shimingshenhecount)?'0':$shimingshenhecount;
        if ($shimingshenhecount != session('info.shimingshenhecount')){
            session('info.shimingshenhecount',$shimingshenhecount);
        }

        // 查询待回复的询价数量并存入session
        $askcount = db('ask')
            ->where('status',1)
            ->count('id');
        $askcount = empty($askcount)?'0':$askcount;
        if ($askcount != session('info.askcount')){
            session('info.askcount',$askcount);
        }


        // 权限控制
        if(!session('?username')){
            $this->error('你还未登录!', url('admin/Index/login'),'',2);
        }else{
            if(session('username') != 'admin') {
                $node = session('node');
//
                if (!in_array(strtolower($wantnode), $node)) {
                    $this->error('您没有访问权限');
                }
            }
        }
    }
}
